Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Document internals of logging system #2028

Closed
wants to merge 1 commit into from

Conversation

tylerjw
Copy link
Contributor

@tylerjw tylerjw commented Oct 17, 2021

Signed-off-by: Tyler Weaver [email protected]

Closes #2026

@JafarAbdi would you mind reviewing this for correctness and completeness? You recently had to trace this code to create your PR against it for file based configuration.

@clalancette here is my initial attempt at documenting this. Would you mind reviewing this for structure, organization, and completeness from a high level? I'm unsure how to organize this documentation within the existing page(s) describing the logging system.

@tylerjw
Copy link
Contributor Author

tylerjw commented Oct 17, 2021

Here are warnings that I get when I build locally. I need to read up on rst syntax and fix these:

/home/tyler/code/websites/ros2_documentation/source/Concepts/About-Logging.rst:139: WARNING: 'any' reference target not found: ../Tutorials/Logging-and-logger-configuration.html#logger-level-configuration-command-line
/home/tyler/code/websites/ros2_documentation/source/Concepts/About-Logging.rst:229: WARNING: 'any' reference target not found: INFO
/home/tyler/code/websites/ros2_documentation/source/Concepts/About-Logging.rst:256: WARNING: 'any' reference target not found: isatty

Copy link

@JafarAbdi JafarAbdi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tylerjw Thank you for starting this effort!

There is currently only one external library interface defined and that is ``rcl_logging_spdlog``.
The external-lib implementation is set during the CMake configure step of the package ``rcl``.
It can be overridden with the variable ``RCL_LOGGING_IMPLEMENTATION``.
The ``rcl_logging`` README says there is a ``rcl_logging_log4cxx`` implementation, however that does not appear to exist yet.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was supported previously and got removed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe another PR can be created updating the rcl_logging README, or at least an issue opened?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The ``rcl_logging`` README says there is a ``rcl_logging_log4cxx`` implementation, however that does not appear to exist yet.

Comment on lines +48 to +56
Log files
---------

Log output files written to a directory that defaults to ``~/.ros/log`` but can be changed through enviroment variables. The filenames follow this pattern:

``<exe>_<pid>_<milliseconds-since-epoch>.log``

These are created per operating system process.
The external lib logging using ``spdlog`` is what writes these files in the current implementation.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move this part to https://github.com/ros2/ros2_documentation/blob/rolling/source/Tutorials/Logging-and-logger-configuration.rst?, I see there's a section about Logging directory configuration

Logging from a Python ROS Node
------------------------------

The Python interfaces are built on top of ``rclcpp`` and therefore share the same functionality.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely not true; rclcpp and rclpy are siblings. It may be true that rclpy depends on rcl, though I'm not sure of that; Python has robust logging facilities of its own, we may be using those instead.

Copy link
Contributor

@clalancette clalancette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good start to this documentation.

That said, adding this information to this document mixes up the user-facing portion of the Concept with the technical details on how things are implemented. I might suggest that we split this into two documents; the current Concepts/About-Logging.rst talks about the logging system from the users POV (with some additional notes from what you've written below), and then a new Concepts/Logging-Implementation.rst which describes how it is implemented. What do you think?

@clalancette clalancette self-assigned this Nov 11, 2021
Copy link
Member

@audrow audrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like great content to add. I agree with @clalancette about splitting it up.

Some general feedback, that may be more from it being a "Draft" state is that there are several times that things are implicitly referenced (e.g., "This is necessary because..." and "One implication of this is..."). It is often not clear to me what "this" is referring to. It would be good to be more specific, even if you feel it is a bit needlessly wordy.

Compiling out logging
^^^^^^^^^^^^^^^^^^^^^

To compile wihtout logging set ``RCLCPP_LOGGING_ENABLED=0`` and ``RCLCPP_LOG_MIN_SEVERITY=RCLCPP_LOG_MIN_SEVERITY_NONE``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To compile wihtout logging set ``RCLCPP_LOGGING_ENABLED=0`` and ``RCLCPP_LOG_MIN_SEVERITY=RCLCPP_LOG_MIN_SEVERITY_NONE``.
To compile without logging, set ``RCLCPP_LOGGING_ENABLED=0`` and ``RCLCPP_LOG_MIN_SEVERITY=RCLCPP_LOG_MIN_SEVERITY_NONE``.

Comment on lines +78 to +82

One implication of this is that in any ROS process based on ``rclcpp`` it is single-threaded during logging.
To combat the performance implications of this you can use throttling.
This is necessary because the logging system writes to file streams (stderr, stdout, normal files) which cannot be done from multiple threads in a sane way.
A possible technique to log from a thread you need to be lock-free would be to use internal queues to send data to another thread that then logs your data.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
One implication of this is that in any ROS process based on ``rclcpp`` it is single-threaded during logging.
To combat the performance implications of this you can use throttling.
This is necessary because the logging system writes to file streams (stderr, stdout, normal files) which cannot be done from multiple threads in a sane way.
A possible technique to log from a thread you need to be lock-free would be to use internal queues to send data to another thread that then logs your data.
One implication of this is that in any ROS process based on ``rclcpp`` is single-threaded during logging.
This is necessary because the logging system writes to file streams (stderr, stdout, normal files) which cannot easily be done from multiple threads.

I think this paragraph can have some explanation cut and can be combined with the above paragraph.

Maybe add the cutout segments as notes, for example.


To compile wihtout logging set ``RCLCPP_LOGGING_ENABLED=0`` and ``RCLCPP_LOG_MIN_SEVERITY=RCLCPP_LOG_MIN_SEVERITY_NONE``.

Will this only work with a source build of ros2 or can this be done per project that depends on ros2?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Will this only work with a source build of ros2 or can this be done per project that depends on ros2?
Will this only work with a source build of ROS 2, or can this be done per project that depends on ROS 2?

We prefer "ROS 2."

rclcpp ``Logger`` class
^^^^^^^^^^^^^^^^^^^^^^^

Stores a name string.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Stores a name string.
The ``Logger`` class stores a name string, which is used to identify the logger.

``RCLCPP`` macros
^^^^^^^^^^^^^^^^^

Defined by generated header in rclcpp (rclcpp/resource/logging.hpp.em).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to make the first lines of sections full sentences, or to format them differently, in a way that clearly indicates this is a definition.

rosout logging
^^^^^^^^^^^^^^

Publishes a ``rcl_interfaces::Log`` message to the topic /node-name/rosout.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Publishes a ``rcl_interfaces::Log`` message to the topic /node-name/rosout.
Publishes a ``rcl_interfaces::Log`` message to the topic ``/node-name/rosout``.

There is currently only one external library interface defined and that is ``rcl_logging_spdlog``.
The external-lib implementation is set during the CMake configure step of the package ``rcl``.
It can be overridden with the variable ``RCL_LOGGING_IMPLEMENTATION``.
The ``rcl_logging`` README says there is a ``rcl_logging_log4cxx`` implementation, however that does not appear to exist yet.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe another PR can be created updating the rcl_logging README, or at least an issue opened?

There is currently only one external library interface defined and that is ``rcl_logging_spdlog``.
The external-lib implementation is set during the CMake configure step of the package ``rcl``.
It can be overridden with the variable ``RCL_LOGGING_IMPLEMENTATION``.
The ``rcl_logging`` README says there is a ``rcl_logging_log4cxx`` implementation, however that does not appear to exist yet.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The ``rcl_logging`` README says there is a ``rcl_logging_log4cxx`` implementation, however that does not appear to exist yet.

RCUTILS internals
-----------------

``rcutils`` contains macros and functions that define some of the non-ros low-level logging behavior in C.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
``rcutils`` contains macros and functions that define some of the non-ros low-level logging behavior in C.
``rcutils`` contains macros and functions that define some of the non-ROS low-level logging behavior in C.

- Don't use colours.

If it is unset, colors are used depending on if the target stream is a terminal or not.
See `isatty` documentation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to add a link here.

@clalancette
Copy link
Contributor

Closing in favor of the just merged #3025. It doesn't have quite as much detail as this one has, but I think it is good enough for the end-user to understand what is going on. We should probably have a separate design document somewhere about the real internals of the logging subsystem, but that would probably live in https://github.com/ros-infrastructure/rep .

@tylerjw tylerjw deleted the logging-concepts branch September 23, 2022 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Documentation for the existing logging system
4 participants